# distribution/hw03/modLightweightActor.py        David MacQuigg ece373 10/22/07
'''Python version of distibution.hw03.LightweightActor.java and its two related
classes, Port and PortMismatchException.'''

class LightweightActor(object):  # an abstract class (for subclassing only)
    '''
/**
 * A LightweighActor performs some action on fire, depending on
 * the value of its input and output Ports. The extending class
 * must decide how many of each of these Ports makes sense,
 * and whether certain types on ports require alternative actions.
 * 
 * In addition, each extending class is required to instantiate the
 * inputPort and outputPort member variables, to ensure that the
 * List is of the appropriate kind (List is an abstract class).
     '''
    def fire(self):
        '''
        /**
         * Do the 'major' thing this actor should do. This is where
         * all the action is. 
         * @throws PortMismatchException
         */
         '''
    def getInputPorts(self):
        '''Returns all of the input ports of this actor'''
        return self._inputPorts

    def getOutputPorts(self):
        '''Returns all of the output ports of this actor'''
        return self._outputPorts

    def setInputPort(self, nPortNumber, port):
        '''
        /**
         * Establish the certain input Port to be a certain object. Note that
         * this may include the output Port of another actor.
         * 
         * @param nPortNumber The logical number of the port (0-indexed)
         * @param port The object to assign.
         */
        '''
        

class Port(object):
    '''A generic container for port _objects'''
    
    def __init__(self, obj=object):
        self._obj = obj

    def setValue(self, obj):
        self._obj = obj
    
    def getValue(self):
        return self._obj

    def __str__(self):
        return self._obj.__str__()


class PortMismatchException(Exception):
    '''Raised when the input ports do not match sufficiently to perform the
       action.'''
